/*
 * @Author: your name
 * @Date: 2021-10-16 09:26:44
 * @LastEditTime: 2021-10-16 10:20:20
 * @LastEditors: Please set LastEditors
 * @Description: v 尽量填满v
 * @FilePath: \luogu\动态规划\模板问题\复习代码\1049.cpp
 */

#include<iostream>
using namespace std;
#include<algorithm>

int f[35][20010];
//开销j空间获得最大的价值
int ff[20010];

int v[35];

int main(){
    int objv,n;
    cin >> objv >> n;
    for(int i=1; i<=n; i++){
        cin >> v[i];
        for(int j=0; j<=objv; j++){
            //当前
            f[i][j] = f[i-1][j];
            if(j >= v[i]) f[i][j] = max(f[i-1][j],f[i-1][j-v[i]]+v[i]);
        }
        for(int j=objv; j>=v[i]; j--){
            ff[j] = max(ff[j-v[i]]+v[i],ff[j]);
        }
        cout << endl;
    }
    cout << f[n][objv] << endl;
    cout << ff[objv] << endl;
    return 0;
}